package org.swirrel;

import javax.swing.JFrame;
import javax.swing.JButton;
import org.swirrel.component.SwFrame;
import org.swirrel.annotation.ActionPerformed;
import javax.swing.JPanel;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import org.swirrel.annotation.MouseClicked;
import org.swirrel.annotation.MouseEntered;
import org.swirrel.annotation.MouseExited;
import org.swirrel.annotation.MousePressed;
import org.swirrel.annotation.WindowIconified;
import static java.awt.BorderLayout.*;

@Deprecated /* use the examples from org.swirrel.example like TabbedExampleSwFrame for testing */
public class TestFrame extends SwFrame {

    @ActionPerformed("buttonPressed")
    private JButton button = new JButton("Press me!");
    @MouseClicked("mouseClicked")
    @MousePressed("mousePressed")
    @MouseEntered("mouseEnteredOrExited")
    @MouseExited("mouseEnteredOrExited")
    private JLabel label = new JLabel("MouseTester");

    public TestFrame() {
        super("Test");
        setSize(500, 500);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        getContentPane().add(button);
        getContentPane().add(new TestPanel(), SOUTH);
        getContentPane().add(label, WEST);
    }

    private void buttonPressed(ActionEvent ae) {
        System.out.println("Press harder, I can take it! " + ae.toString());
    }

    private void leftPressed() {
        System.out.println("You pressed left!");
    }

    private void mouseClicked() {
        System.out.println("Mouse clicked");
    }

    private void mousePressed(Object e) {
        System.out.println("Mouse pressed " + e);
    }

    private void mouseEnteredOrExited() {
        System.out.println("Mouse entered or exited");
    }

    public static void main(String... args) throws Exception {
        JFrame frame = new TestFrame() {

            @WindowIconified("schwarzenegger")
            JFrame myself = this;

            {
                getContentPane().add(new TestPanel(), NORTH);
                setVisible(true);
            }

            private void schwarzenegger() {
                System.out.println("I'll be back!");
            }
        };
    }

    private static class TestPanel
            extends JPanel {

        @ActionPerformed("leftPressed")
        JButton leftButton = new JButton("Left");
        @ActionPerformed("rightPressed")
        JButton rightButton = new JButton("Right");

        private TestPanel() {
            add(leftButton);
            add(rightButton);
        }

        private void rightPressed() {
            System.out.println("You pressed right!");
        }
    }
}
